package org.example.controller;

import org.example.service.SessionService;

public class SessionController extends BaseController {
    private final SessionService sessionService;

    public SessionController(SessionService sessionService) {
        this.sessionService = sessionService;
    }

    @Override
    public String handleRequest() {
        try {
            Integer customerId = getIntPathParam("customerId");
            if (customerId == null) {
                return "ERROR:400:Invalid path - missing or invalid customerId";
            }

            String sessionKey = sessionService.getOrCreateSession(customerId);
            return "SUCCESS:200:" + sessionKey;

        } catch (Exception e) {
            e.printStackTrace();
            return "ERROR:500:Internal Server Error";
        }
    }
}